<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String ctx = request.getContextPath();
    request.setAttribute("ctx", ctx);
%>
<html>
<head>
    <title>Title</title>
    <script src="${ctx}/bootstrap/jquery-1.9.1.min.js"></script>
    <link rel="stylesheet" href="${ctx}/css/index_work.css">
</head>
<body>
    <form action="${ctx}/list.do">
        <input type="hidden" name="pageNum">
        店铺名称<input type="text" name="dname" value="${dianpu.dname}">
        开始时间<input type="date" name="beginDate" value="${dianpu.beginDate}">
        结束时间<input type="date" name="endDate" value="${dianpu.endDate}">
        <input type="submit" value="查询">
        <a href="${ctx}/toadd.do">添加</a>
        <a href="##" onclick="fanxuan()">反选</a>
        <a href="##" onclick="deletebth('')">批量删除</a>
    </form>
    <table>
        <tr>
            <td>编号<input type="checkbox" onclick="quanxuan(this)"></td>
            <td>店铺名称</td>
            <td>创建时间</td>
            <td>图片</td>
            <td>商品</td>
            <td>编辑</td>
        </tr>
        <c:forEach items="${pageInfo.list}" var="var" varStatus="vs">
            <tr>
                <td>${vs.index+pageInfo.startRow}<input type="checkbox" name="did" value="${var.did}"></td>
                <td>${var.dname}</td>
                <td>${var.create_date}</td>
                <td><img src="${var.img}" style="width: 30px;height: 30px"></td>
                <td>
                    <c:forEach items="${var.shopList}" var="shop" varStatus="vs1">
                        <c:if test="${vs1.index>0}">
                            |
                        </c:if>
                        ${shop.sname}
                    </c:forEach>
                </td>
                <td><a href="${ctx}/toadd.do?did=${var.did}">修改</a>
                    <a href="${ctx}/detail.do?did=${var.did}">详情</a>
                    <a href="##" onclick="deletebth(${var.did})">删除</a></td>
            </tr>
        </c:forEach>
    </table>
   <a href="##" onclick="fenye(1)">首页</a>
    <a href="##" onclick="fenye(${pageInfo.isFirstPage?1:pageInfo.prePage})">上一页</a>
    <a href="##" onclick="fenye(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">下一页</a>
    <a href="##" onclick="fenye(${pageInfo.pages})">尾页</a>
    共${pageInfo.total}条数据
<script>
    function fenye(pageNum) {
        $("[name='pageNum']").val(pageNum);
        $("form").submit();
    }
    function quanxuan(obj) {
        $('[name="did"]').prop("checked",$(obj).prop("checked"));
    }
    function fanxuan() {
        $('[name="did"]').each(
            function () {
                $(this).prop("checked",!$(this).prop("checked"));
            }
        )
    }
    function deletebth(did) {
        var dids=[];
        if(did != ""){
            dids.push(did);
        } else{
            $('[name="did"]:checked').each(function () {
                dids.push($(this).val());
            })
        }
        if(confirm("您确定要删除吗？"+dids)){
            $.post("${ctx}/deletebth.do?dids="+dids,function (res) {
                if(res){
                    location.reload();
                } else{
                    alert("删除失败");
                }
            })
        }
    }
</script>
</body>
</html>
